package com.itheima.wenjian;

import java.io.File;
import java.util.HashMap;

/**
 * @author zhangbaiyan
 * @date 2024-09-19 18:40
 * @description:
 * @version:
 */
public class test5 {
    public static void main(String[] args) {
        File f = new File("C:\\Users\\17685\\Desktop\\rouyi-906");
        System.out.println(getCount(f));
    }

    public static HashMap<String, Integer> getCount(File f) {
        HashMap<String, Integer> hm = new HashMap<>();
        File[] files = f.listFiles();
       for (File file : files)
           if(file.isFile()){
               String[] split = file.getName().split("\\.");
               if (split.length > 1){
                   String s = split[split.length - 1];
                   if (hm.containsKey(s)){
                       hm.put(s, hm.get(s) + 1);
                   }else {
                       hm.put(s, 1);
                   }
               }
           }else {
               HashMap<String, Integer> count = getCount(file);
               count.forEach((k, v) -> hm.put(k, hm.get(k) == null ? v : hm.get(k) + v));
           }
        return hm;
    }
}
